<?php
namespace Matrix\Controller;

class CodeController extends CommonController {
	
public function __construct() {
		parent::__construct ();
		parent::__config ( array (
				'model_name'=>'Code',
		) );
	}
	
	public function index(){
		parent::__config ( array (
				'sort'=>'code_key',
		) );
		$table =I('table');
		if (!$table == null && ! empty ($table)) {
			parent::__config ( array (
					'display' => 'table' ,
					'display_parms'=>array('table'=>1),
			) );
		};
		parent::index ();
	}
	
	function add() {
		parent::add ();
	}
	function insert() {
		parent::__config ( array (
				'display'=>'index',
		) );
			$codeModel = D("Code");
			$code_talModel = D("CodeTal");
			//$issue = $code_array[0]['Issue'];
			$data['code_key']=I("code_key");
			$data['date']=str_replace("-","",I("date"));
			$data['number']=substr_replace("000",$_POST['number'],-strlen($_POST['number']));
			
			$data['h1'] = I("h1");
			$data['h2'] = I("h2");
			$data['h3'] = I("h3");
			$data['h4'] = I("h4");
			$data['h5'] = I("h5");
			$data['hm']=$data['h1'].$data['h2'].$data['h3'].$data['h4'].$data['h5'];
			//后2
			if($data['h5']==$data['h4']){
				$data['hou2']='对子';
			}else{
				$data['hou2']='';
			}
// 		后3(组六，组三，豹子)
			if($data['h3']==$data['h4']&&$data['h4']==$data['h5']){
				$data['hou3']='豹子';
			}else if($data['h3']==$data['h4']||$data['h3']==$data['h5']||$data['h4']==$data['h5']){
				$data['hou3']='组三';
			}else{
				$data['hou3']='组六';
			}
			$data['time']=date("Y-m-d H:i:s",time());
			$codeModel->add($data);
			$code_talModel->add($data);
			$this->redirect('Code/index');
// 			parent::insert ($data);

	}
	
	function foreverdelete() {
		parent::__config ( array (
				'display' => 'index?table=1' ,
		) );
		parent::foreverdelete ();
	}
	
	function edit() {
		parent::edit ();
	}
	
	function update() {
		parent::__config ( array (
				'display'=>'index',
		) );
		
		$p1 = getNumberAll($_POST['p_1'],false,$_POST['date'])[0];
		$p2 = getNumberAll($_POST['p_2'],false,$_POST['date'])[0];
		$p3 = getNumberAll($_POST['p_3'],false,$_POST['date'])[0];
		$p4 = getNumberAll($_POST['p_4'],false,$_POST['date'])[0];
		$p5 = getNumberAll($_POST['p_5'],false,$_POST['date'])[0];
		$p6 = getNumberAll($_POST['p_6'],false,$_POST['date'])[0];
		$tm = getNumberAll($_POST['tm'],true,$_POST['date'])[0];
		$data['date']=$_POST['date'];
		$temp_y = substr($_POST['date'],0,4);
		$temp_m = substr($_POST['date'],5,2);
		$temp_r = substr($_POST['date'],8,2);
		$data['new_date']=$temp_y.'年'.$temp_m.'月'.$temp_r.'日';
		$data['old_date']= $tm['old_time'][4].'月'.$tm['old_time'][5].'日';
		$data['date_num']=substr_replace("000",$_POST['date_num'],-strlen($_POST['date_num']));
		$data['Code_key']=$temp_y.substr_replace("000",$_POST['date_num'],-strlen($_POST['date_num']));
		//星期
		$rows=array("星期日","星期一","星期二","星期三","星期四","星期五","星期六");
		$week_num = date("w",strtotime($_POST['date']));//星期
		$data['week']=$rows[$week_num];
		$data['p_1']=$p1['number'];
		$data['x_1']=$p1['sx'];
		$data['b_1']=$p1['bs'];
		$data['p_2']=$p2['number'];
		$data['x_2']=$p2['sx'];
		$data['b_2']=$p2['bs'];
		$data['p_3']=$p3['number'];
		$data['x_3']=$p3['sx'];
		$data['b_3']=$p3['bs'];
		$data['p_4']=$p4['number'];
		$data['x_4']=$p4['sx'];
		$data['b_4']=$p4['bs'];
		$data['p_5']=$p5['number'];
		$data['x_5']=$p5['sx'];
		$data['b_5']=$p5['bs'];
		$data['p_6']=$p6['number'];
		$data['x_6']=$p6['sx'];
		$data['b_6']=$p6['bs'];
		$data['tm']=$tm['number'];
		$data['sx']=$tm['sx'];
		$data['ds']=$tm['ds'];
		$data['bs']=$tm['bs'];
		$data['dx']=$tm['dx'];
		$data['wx']=$tm['wx'];
		$data['tt']=$tm['tt'];
		$data['ws']=$tm['ws'];
		$data['hds']=$tm['hds'];
		$data['jy']=$tm['jy'];
		$data['ms']=$tm['ms'];
		$data['dw']=$tm['dw'];
		$data['yy']=$tm['yy'];
		$data['td']=$tm['td'];
		$data['jx']=$tm['jx'];
		$data['hb']=$tm['hb'];
		$data['sex']=$tm['sex'];
		$data['bh']=$tm['bh'];
		$data['nv']=$tm['nv'];
		$zh = $_POST['p_1']+$_POST['p_2']+$_POST['p_3']+$_POST['p_4']+$_POST['p_5']+$_POST['p_6']+$_POST['tm'];
		if($zh<=175){
			$data['zh']='('.$zh.')≤176';
		}else {
			$data['zh']='('.$zh.')≥175';
		}
		$zh_gw = substr($zh,-1);//总和个位
		if(($zh_gw%2)==0){
			$data['zhds']='双';
		}else{
			$data['zhds']='单';
		}
		$data['id']=$_POST['id'];
		parent::update ($data);
	}
	
	
	
	
	function bean() {
		parent::bean();
	}
	
	function sort() {
		parent::sort ();
	}
	
	function excelImport(){
		parent::__config ( array (
				'model_name'=>'Code',
				'display' => 'index' ,
				'display_parms'=>array('table'=>1),
		) );
		$result = parent::excelImport();
		dump($result);
	}
	
	function excelOutput(){
// 		parent::__config ( array (
// 				'model_name'=>'WifiAdmin',
// 				'excel'=>array('headArr'=>array('序号'=>'id','姓名'=>'name','年龄'=>'grade'),'output'=>array('A'=>'id','B'=>'name','C'=>'grade'))
// 		) );
// 		parent::excelOutput();
	}
	
}